package com.yi.wood.gob.gate;

import com.yi.wood.gob.gate.handler.GobHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by moyi on 2018/9/20 10:05
 *
 * @author moyi
 * 实际处理类注册
 */
@Service
public class GobInitializer extends ChannelInitializer<SocketChannel> {

    @Resource
    private GobHandler gobHandler;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //30秒没有通信，则触发idle消息。
        ch.pipeline().addLast(new IdleStateHandler(30, 0, 0));
        ch.pipeline().addLast("http-codec", new HttpServerCodec());
        ch.pipeline().addLast("aggregator",new HttpObjectAggregator(65536));
        ch.pipeline().addLast("http-chunked",new ChunkedWriteHandler());
        ch.pipeline().addLast(gobHandler);
    }
}
